package com.atguigu.springcloud.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


//RabbitMQ-CORE配置
@Configuration
public class RabbitMQ_CORE_Config {

	//交换机
	@Bean
	public DirectExchange SUND_EXCHANGE_DIRECT() {
		return new DirectExchange("directExchange-1", true, false);
	}

	//队列-SIMPLE-日志服务-CORE
	@Bean
	public Queue SUND_QUEUE_SIMPLE_CENTER_CORE() {
		return new Queue("queue-1", true, false, false);
	}


	//路由键-SIMPLE-日志服务-CORE
	@Bean
	Binding SUND_ROUTINGKEY_SIMPLE_CENTER_CORE() {
		return BindingBuilder.bind(SUND_QUEUE_SIMPLE_CENTER_CORE()).to(SUND_EXCHANGE_DIRECT())
				.with("routingKey1");
	}

	//队列-RPC-中心-CORE
	@Bean
	public Queue SUND_QUEUE_RPC_CENTER_CORE() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("x-message-ttl", RabbitMQConst.SUND_RPC_MESSAGE_TTL);
		map.put("x-dead-letter-exchange", RabbitMQConst.SUND_EXCHANGE_DEAD);
		map.put("x-dead-letter-routing-key", RabbitMQConst.SUND_ROUTINGKEY_DEAD);
		return new Queue(RabbitMQConst.SUND_QUEUE_RPC_SERVICE_CORE, true, false, false, map);
	}
	//路由键-RPC-中心-CORE
	@Bean
	Binding SUND_ROUTINGKEY_RPC_CENTER_CORE() {
		return BindingBuilder.bind(SUND_QUEUE_RPC_CENTER_CORE()).to(SUND_EXCHANGE_DIRECT())
				.with(RabbitMQConst.SUND_ROUTINGKEY_RPC_SERVICE_CORE);
	}
}
